<?php
session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
$adminid=$_SESSION['adminid'];
$id = isset($_GET['id'])?$_GET['id']:'';
$act = isset($_GET['act'])?$_GET['act']:'';
if($_GET['act']=='detail')
{
	$selrow = $dbconn->fetch($dbconn->query("select b.*,p.img from ".DBQIAN."buylog b join ".DBQIAN."product p on b.product_id=p.id where b.id=$id"));
	$user = $dbconn->fetch($dbconn->query("select * from ".DBQIAN."users where id=".$selrow['users_id']));
	switch ($selrow['status'])
	{
		case 1: $selrow['status']="等待买家付款";break;
		case 2: $selrow['status']="等待店铺发货";break;
		case 3: $selrow['status']="等待买家付款";break;
		case 4: $selrow['status']="等待买家收货";break;
		case 5: $selrow['status']="等待店铺发货";break;
		case 6: $selrow['status']="交易完成";break;
		case 7: $selrow['status']="订单已关闭";break;
		case 8: $selrow['status']="订单被卖家关闭";break;
	}
}
//添加
if($_GET['act']=='add'){
	//print_r($_FILES['img']);exit;
	if ($_FILES&&!empty($_FILES['img']['name']))
	{
		$result = upload($_FILES['img']);
		//print_r($result);exit;
		if ($result&&$result['result'] == 1)
		{
			$img = $result['path'];
			unlink($selrow['img']);
		}
		else 
		{
			$dbconn->showalert("图片上传失败","product.php",1);	exit;
		}
	}
	else 
	{
		$img = $_POST['img1'];
	}
	//echo $img;exit;
	$name = $_POST['name'];
	$price = $_POST['price'];
	$color = $_POST['color'];
	$size = $_POST['size'];
	$desc = htmlspecialchars($_POST['content1']);//exit;
	$time = date('Y-m-d H:i:s',time());
//	echo 'insert into '.DBQIAN.'product(title,desc,time,content,url) values(\''.$title.'\',\''.$desc.'\',\''.$time.'\',\''.$content.'\',\''.$url.'\')';exit;
	$dbconn->noretquery("update ".DBQIAN."product set `name`='$name',`desc`='$desc',`img`='$img',`time`='$time',`color`='$color',`size`='$size',`price`='$price' where id=".$id);
	$dbconn->showalert("保存成功","product.php",1);
}

function upload($file)
{
	$picname = $file['name'];
	$picsize = $file['size'];
	if ($picname != "") 
	{
		if ($picsize > 1024000) 
		{
			echo '图片大小不能超过1M';
			exit;
		}
		$type = strstr($picname, '.');
		if ($type != ".gif" && $type != ".jpg" && $type != ".png") 
		{
			echo '图片格式不对！';
			exit;
		}
		$rand = rand(100, 999);
		$pics = date("YmdHis") . $rand . $type;
		//上传路径
		$pic_path = "../user/images/product/". $pics;
		$result = move_uploaded_file($file['tmp_name'], $pic_path);
	}
	$arr = array(
		'name'=>$picname,
		'path'=>$pic_path,
		'pic'=>$pics,
		'size'=>$size,
		'result'=>$result
	);
	return $arr;
}

?><!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>欢迎登录后台管理系统</title>
<link href="css/base.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css">
<!--<link href="css/select.css" rel="stylesheet" type="text/css">-->
<link rel="stylesheet" href="k/themes/default/default.css" />
<link rel="stylesheet" href="k/plugins/code/prettify.css" />
<script charset="utf-8" src="k/kindeditor.js"></script>
<script charset="utf-8" src="k/lang/zh_CN.js"></script>
<script charset="utf-8" src="k/plugins/code/prettify.js"></script>
<script src="js/jquery.js"></script>
<script src="js/select-ui.min.js"></script>
<script type="text/javascript" src="js/uploadPreview.js"></script>
<style>
textarea{border-top: solid 1px #a7b5bc;border-left: solid 1px #a7b5bc;border-right: solid 1px #ced9df;border-bottom: solid 1px #ced9df;padding:5px;line-height:20px}
p{line-height:32px}
tr td{border-right: 1px solid #dddddd;}
hr{background: #dddddd;height: 1px;}
.hengfu{margin:10px auto;}
.orderdetail{}
.orderdetail tr{height:25px}
.orderdetail tr td{width:33.3%}
</style>
<script>
$(document).ready(function(){
   $(function(){
   		$("#time").datetimepicker();
   		/*$(\'#img\').change(function(){
			alert(123);return false;
			var objUrl = getObjectURL(this.files[0]) ;
			console.log("objUrl = "+objUrl) ;
			if (objUrl) {
				$("#img0").attr("src", objUrl) ;
			}
		}) ;*/
   });
   
});

function getObjectURL(file) {
	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}
</script>
</head>
<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="index.php">首页</a></li>
    <li><a href="orderlist.php">订单管理</a></li>
    <li>编辑</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>订单详情</span></div>
  <div style="width:1200px;margin: auto;">
	<p style="font-size: 13px;">购买id:<a href="hyrecord.php?username=<?=$user['username']?>"><?=$user['name'].'('.$user['username'].')'?></a></p>
  </div>
  <form name="radd" method="post" action="?act=add&id=<?=$selrow['id']?>" enctype="multipart/form-data">
    <table style="width:1200px;text-align: center;color: #404040;border: 1px solid #dddddd;margin: auto;">
  	<tr style="background: #d6e8f3;height: 50px;">
  		<th>商品</th>
  		<th>商品属性</th>
  		<th>状态</th>
  		<th>支付情况</th>
  		<th>单价</th>
  		<th>数量</th>
  		<th>优惠</th>
  		<th>总价</th>
  	</tr>
  	<tr>
  		<td style="width:28%">
  			<img style="width: 50px;float: left;margin: 20px;" src="<?=$selrow['img']?>" id="img" >
  			<span style="float: left;margin-top: 20px;"><?=$selrow['product_name']?></span>
  		</td>
  		<td>
  			<span>颜色分类：<?=$selrow['color']?></span><br>
  			<span>尺码：<?=$selrow['size']?></span>
  		</td>
  		<td>
  			<p><?=$selrow['status']?></p>
  		</td>
  		<td>
  			<p><?=$selrow['paystatus']?"<font color='green'>已支付</font>":"<font color='red'>未支付</font>"?></p>
  		</td>
  		<td>
  			<p><?=$selrow['price']?></p>
  		</td>
  		<td>
  			<p><?=$selrow['quantity']?></p>
  		</td>
  		<td>
  			<p><?=$selrow['yh_price']?></p>
  		</td>
  		<td>
  			<p><?=$selrow['amount']?></p>
  		</td>
  	</tr>
  </table>
  <div style="width:1200px;margin: auto;">
  	  <div class="hengfu" style="height:50px;">
	  	 <p style="float:right">订单总金额：<span style="color:#F40;font-size:28px"><?=$selrow['should_pay']?></span></p>
	  </div>
  	  <div class="hengfu">
	  	 <span style="border-bottom: 2px solid gray;">收货信息</span>
		 <hr>
	  </div>
	  <div>
	  	 <p><span>收货地址:</span>&nbsp;&nbsp;<?=$selrow['name'].', '.$selrow['tel'].', '.$selrow['province'].' '.$selrow['city'].' '.$selrow['address']?></p>
	  </div>
	  <div>
	  	 <p><span>订单备注:</span>&nbsp;&nbsp;<?=$selrow['note']?></p>
	  </div>
  	  <div class="hengfu">
	  	 <span style="border-bottom: 2px solid gray;">订单信息</span>
		 <hr>
	  </div>
	  <table class="orderdetail" style="width:1200px;color: #404040;margin: auto;">
		 <tr>
		 	<td>订单编号：<?=$selrow['ordernumber']?></td>
		 	<td>创建时间：<?=$selrow['create_time']?></td>
		 	<td>物流单号：<?=$selrow['shippingnumber']?></td>
		 </tr>
		 <tr>
		 	<td>支付时间：<?=$selrow['paytime']?></td>
		 	<td>发货时间：<?=$selrow['shiptime']?></td>
		 	<td>成交时间：<?=$selrow['goods_time']?></td>
		 </tr>
	  </table>
  </div>
  </form>
</div>
<script>
	KindEditor.ready(function(K) {
		var editor1 = K.create(\'textarea[name="content1"]\', {
			cssPath : 'k/plugins/code/prettify.css',
			uploadJson : 'k/php/upload_json.php',
			fileManagerJson : 'k/php/file_manager_json.php',
			allowFileManager : true,
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
					K('form[name=radd]')[0].submit();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
					K('form[name=radd]')[0].submit();
				});
			}
		});
		prettyPrint();
	});
</script>
</body>
</html>